import { fileURLToPath, URL } from 'node:url'

import { defineConfig } from 'vite'
import vue from '@vitejs/plugin-vue'
import WindiCSS from 'vite-plugin-windicss'
import path from 'node:path'
import AutoImport from 'unplugin-auto-import/vite'
import Components from 'unplugin-vue-components/vite'
import { ElementPlusResolver } from 'unplugin-vue-components/resolvers'

// https://vitejs.dev/config/
export default defineConfig({
  base: "./",
  server: {
    proxy: {
      '/api': {
        // target: 'http://00.000.105.221:8081',
        //线上部署的话采用服务器地址提供的后端接口
        target: 'http://localhost:8081',
        changeOrigin: true,
        rewrite: (path) => path.replace(/^\/api/, ''),
      },
    },
    // host:'0.0.0.0' ,//ip地址
    // port: 8080, // 设置服务启动端口号
    // open: true, // 设置服务启动时是否自动打开浏览器
  },
  plugins: [
    vue(), 
    WindiCSS(),
    AutoImport({
      resolvers: [ElementPlusResolver()],
    }),
    Components({
      resolvers: [ElementPlusResolver()],
    }),
  ],
  resolve: {
    alias: {
      '@': fileURLToPath(new URL('./src', import.meta.url)),
      // 指定 src 文件夹别名，以便快速定位到此文件夹
      // "~": path.resolve(__dirname, "src")
    }
  }
})
